/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     TreeNode *left;
 *     TreeNode *right;
 *     TreeNode() : val(0), left(nullptr), right(nullptr) {}
 *     TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
 *     TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
 * };
 */
class Solution {

public:
    vector<TreeNode*> createTree(int start,int end){

        if(start>end){
            return {nullptr};
        }
        vector<TreeNode*> vecTree;
        for(int i=start;i<=end;++i){
            vector<TreeNode*> vecLeft=createTree(start,i-1);
            vector<TreeNode*> vecRight=createTree(i+1,end);
            for(auto& left:vecLeft){
                for(auto& right:vecRight){
                    TreeNode* root=new TreeNode(i);
                    root->left=left;
                    root->right=right;
                    vecTree.push_back(root);
                }
            }
        }

        return vecTree;
    }
    vector<TreeNode*> generateTrees(int n) {
        
        if(!n){
            return {};
        }
        return createTree(1,n);
    }
};
